function reander(hashCode) {
    const fixVal = fixEl.value
    const tableName = tableNameEl.value
    const sqlValue = sqlInputEl.value
    var sqlValueContent = '';
    var htmlContent = '';
    htmlContent += '<div>8 张表:<span style="margin-left: 20px;">' + (hashCode % 8) + '</span></div>'
    htmlContent += '<div>10 张表:<span style="margin-left: 20px;">' + (hashCode % 10) + '</span></div>'
    htmlContent += '<div>16 张表:<span style="margin-left: 20px;">' + (hashCode % 16) + '</span></div>'
    htmlContent += '<div>32 张表:<span style="margin-left: 20px;">' + (hashCode % 32) + '</span></div>'
    htmlContent += '<div>40 张表:<span style="margin-left: 20px;">' + (hashCode % 40) + '</span></div>'
    htmlContent += '<div>64 张表:<span style="margin-left: 20px;">' + (hashCode % 64) + '</span></div>'
    htmlContent += '<div>128 张表:<span style="margin-left: 20px;">' + (hashCode % 128) + '</span></div>'
    htmlContent += '<div>256 张表:<span style="margin-left: 20px;">' + (hashCode % 256) + '</span></div>'
    htmlContent += '<br>'
    if(fixVal && !isNaN(parseInt(fixVal))){
        htmlContent += '<div>'+fixVal+' 张表:<span style="margin-left: 20px;">' + (hashCode % fixVal) + '</span></div>'
    }
    contentEl.innerHTML = hashCode === 0 ? '分页标识无效' : htmlContent;

    var yiqbTableInfoContent = '';
    for (var yiqbTable in yiqbTableBox){
        if(!tableName || yiqbTable.indexOf(tableName) !== -1){
            yiqbTableInfoContent += '<div>'+ yiqbTable + '_' + (hashCode % yiqbTableBox[yiqbTable]) + '</div>'
        }

        if(sqlValue && sqlGroupEl.value === 'yiqb' && sqlValue.indexOf(yiqbTable) > -1) {
            for (let i = 0; i < yiqbTableBox[yiqbTable]; i++) {
                if(sqlValue.indexOf(yiqbTable + '`') > -1) {
                    sqlValueContent += sqlValue.replace(yiqbTable + '`', yiqbTable + '_' + i + '`') + '\n'
                }else{
                    sqlValueContent += sqlValue.replace(yiqbTable + ' ', yiqbTable + '_' + i + ' ') + '\n'
                }
            }
        }
    }
    yiqbTableInfoEl.innerHTML = yiqbTableInfoContent;

    var yiqcTableInfoContent = '';
    for (var yiqcTable in yiqcTableBox){
        if(!tableName || yiqcTable.indexOf(tableName) !== -1){
            yiqcTableInfoContent += '<div>'+ yiqcTable + '_' + (hashCode % yiqcTableBox[yiqcTable]) + '</div>'
        }

        if(sqlValue && sqlGroupEl.value === 'yiqc' && sqlValue.indexOf(yiqcTable) > -1) {
            for (let i = 0; i < yiqcTableBox[yiqcTable]; i++) {
                if(sqlValue.indexOf(yiqcTable + '`') > -1) {
                    sqlValueContent += sqlValue.replace(yiqcTable + '`', yiqcTable + '_' + i + '`') + '\n'
                }else{
                    sqlValueContent += sqlValue.replace(yiqcTable + ' ', yiqcTable + '_' + i + ' ') + '\n'
                }
            }
        }
    }
    yiqcTableInfoEl.innerHTML = yiqcTableInfoContent;

    var yccw1TableInfoContent = '';
    for (var yccw1Table in yccw1TableBox){
        if(!tableName || yccw1Table.indexOf(tableName) !== -1){
            yccw1TableInfoContent += '<div>'+ yccw1Table + '_' + (hashCode % yccw1TableBox[yccw1Table]) + '</div>'
        }

        if(sqlValue && sqlGroupEl.value === 'yccw1' && sqlValue.indexOf(yccw1Table) > -1) {
            for (let i = 0; i < yccw1TableBox[yccw1Table]; i++) {
                if(sqlValue.indexOf(yccw1Table + '`') > -1) {
                    sqlValueContent += sqlValue.replace(yccw1Table + '`', yccw1Table + '_' + i + '`') + '\n'
                }else{
                    sqlValueContent += sqlValue.replace(yccw1Table + ' ', yccw1Table + '_' + i + ' ') + '\n'
                }
            }
        }
    }
    yccw1TableInfoEl.innerHTML = yccw1TableInfoContent;

    var yccw2TableInfoContent = '';
    for (var yccw2Table in yccw2TableBox){
        if(!tableName || yccw2Table.indexOf(tableName) !== -1){
            yccw2TableInfoContent += '<div>'+ yccw2Table + '_' + (hashCode % yccw2TableBox[yccw2Table]) + '</div>'
        }

        if(sqlValue && sqlGroupEl.value === 'yccw2' && sqlValue.indexOf(yccw2Table) > -1) {
            for (let i = 0; i < yccw2TableBox[yccw2Table]; i++) {
                if(sqlValue.indexOf(yccw2Table + '`') > -1) {
                    sqlValueContent += sqlValue.replace(yccw2Table + '`', yccw2Table + '_' + i + '`') + '\n'
                }else{
                    sqlValueContent += sqlValue.replace(yccw2Table + ' ', yccw2Table + '_' + i + ' ') + '\n'
                }
            }
        }
    }
    yccw2TableInfoEl.innerHTML = yccw2TableInfoContent;
    if(sqlValueContent){
        sqlEl.style.height = '150px';
        sqlEl.value = sqlValueContent;
    }else {
        sqlEl.style.height = '20px';
    }
}

function setItem(item) {
    corpIdEl.value = item.split('|')[0];
    corpNameEl.value = item.split('|')[1];
    reander(Math.abs(window.hashCode(corpIdEl.value)));
}

function clearItem(e, item) {
    e.stopPropagation();
    delHistory(item);
    showHistory();
}

function clearHistory() {
    setCookie('history', '', 1)
    showHistory();
}

function addHistory(corpId, corpName){
    var history = getCookie('history') || '[]';
    var historyJson = JSON.parse(history);
    var existEl = historyJson.find(e => e.corpId === corpId);
    if(existEl){
        existEl.corpId = corpId;
        existEl.corpName = corpName || existEl.corpName;
        if(!corpName && existEl.corpName){
            corpNameEl.value = existEl.corpName
        }
    }else {
        historyJson.push({"corpId": corpId, "corpName": corpName})
    }
    setCookie('history', JSON.stringify(historyJson), 60*60*24*365*1000)
}

function delHistory(corpId){
    var history = getCookie('history') || '[]';
    var historyJson = JSON.parse(history);
    var existIndex = historyJson.findIndex(e => e.corpId === corpId);
    if(existIndex !== -1){
        historyJson.splice(existIndex, 1);
    }
    setCookie('history', JSON.stringify(historyJson), 60*60*24*365*1000)
}

function showHistory() {
    var history = getCookie('history') || '[]';
    var historyJson = JSON.parse(history);
    var historyContent = '';
    historyJson.forEach(h => {
        historyContent += '<div class="info" onclick="setItem(\''+h.corpId + '|' + (h.corpName || '') +'\')">'+ h.corpName + ': ' + h.corpId
            +'<i onclick="clearItem(event, \''+h.corpId+'\')">×</i>'
            +'</div>'
    });
    historyEl.innerHTML = historyContent;
}

window.onload = function() {
    showHistory();
}